<?php


namespace app\api\controller;

use app\common\controller\Api;
use think\Env;

class Base extends Api
{
    protected $page = 1;
    protected $limit = 10;
    protected $userinfo;
    protected $isPostMsg = '请求格式错误';//非post请求错误信息
    protected $forbidden = 403;//拒绝请求
    protected $notLogin = 401;//未登录
    protected $userinfoLack = 307;//资料信息不全
    protected $noTeam   = 306;//未完成团队认证
    protected $website = '';
    protected $admin_id;

    public function _initialize()
    {
        parent::_initialize();
        $page     = $this->request->param('page');
        $limit    = $this->request->param('limit');
        $admin_id = $this->request->param('admin_id',null);

        $this->page = (isset($page) && $page > 0) ? $page : $this->page;
        $this->limit = (isset($limit) && $limit > 0) ? $limit : $this->limit;
        $this->website = Env::get('base.website',$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST']);
        $this->admin_id = $admin_id;
    }


    /**
     * 禁止操作
     * @param string $msg    提示信息
     * @param int    $code   错误码，默认为403
     */
    protected function forbidden($msg = '', $code = 403)
    {
        $this->result($msg, null, $code);
    }
    /**
     * 只接受post请求
     */
    public function onlyPost(){
        if(!$this->request->isPost()){
            $this->result($this->isPostMsg, null, $this->forbidden);
        }
    }

    public function getAdminId(){
        if(!$this->admin_id){
            $this->error('缺少admin_id');
        }
        return $this->admin_id;
    }

    public function getImageUrl($array,$value){
        return config('upload.cdnurl').$array[$value];
    }
}